package com.wyc.service.mode.singleton.more;

/**
* 只能产生5个对象
*/
import java.util.ArrayList;
import java.util.Random;

public class Emperors {

    private static ArrayList<Emperors> emperors = new ArrayList<>();
    private Emperors(){}

    static {
        for (int i = 0; i <5 ; i++) {
            emperors.add(new Emperors());
        }
    }

    public static  Emperors getInstance(){
        Random random = new Random();
        return emperors.get(random.nextInt(5));
    }
}
